package com.xiaoq.shop.repository.impl;

import com.xiaoq.shop.entity.TicketSellPlatformEntity;
import com.xiaoq.shop.repository.ITicketSellPlatformRepository;
import org.apache.commons.lang3.StringUtils;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * Created by chenjh on 2018/7/13.
 */
@Repository
public class TicketSellPlatformRepositoryImpl implements ITicketSellPlatformRepository {

    @Autowired
    private Datastore datastore;

    @Override
    public void save(TicketSellPlatformEntity entity) {
        if (entity != null){
            datastore.save(entity);
        }
    }

    @Override
    public TicketSellPlatformEntity getBySitesId(String sitesId) {
        if(StringUtils.isBlank(sitesId)){
            return null;
        }

        Query<TicketSellPlatformEntity> query = datastore.createQuery(TicketSellPlatformEntity.class)
                .filter("sitesId", sitesId);
        return query.get();
    }
}
